package com.example.task.ui;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
import com.example.task.bean.Comment;
import com.example.task.bean.Lecture;
import com.example.task.bean.User;
import com.example.task.R;
import com.example.task.delegate.SimpleDelegateAdapter;
import com.example.task.http.Threads.EvaluateThread;
import com.example.task.http.Threads.GetEvaluateThread;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.xuexiang.xaop.annotation.SingleClick;
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;

import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

import okhttp3.FormBody;
//已弃用
public class EvaluateActivity extends AppCompatActivity {

    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mysignup);
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        User user = (User) bundle.getSerializable("User");
        Lecture lecture = (Lecture) bundle.getSerializable("Lecture");
        List<Lecture> lectureList = new ArrayList<>();
        lectureList.add(lecture);
        TextView textView1 = findViewById(R.id.TextView1);
        textView1.setText(lecture.getActivityName());
        TextView textView2 = findViewById(R.id.TextView2);
        textView2.setText("报名时间：" + lecture.getSignUpTime() + " ~ " + lecture.getDeadlineForSign());
        TextView textView3 = findViewById(R.id.Time);
        textView3.setText("活动时间：" + lecture.getInitDate() + " " + lecture.getAtivityTime() + "-" + lecture.getDeadlineForAtivity());
        TextView textView4 = findViewById(R.id.Place);
        textView4.setText("活动地点：" + lecture.getAtivityPlace());
        TextView textView5 = findViewById(R.id.Principal);
        textView5.setText("负责人工号：" + lecture.getInChargeID());
        TextView textView6 = findViewById(R.id.Phone);
        textView6.setText("联系方式：" + lecture.getInChargeNB());
        TextView textView7 = findViewById(R.id.Type);
        textView7.setText("类型：" + lecture.getType());
        TextView textView8 = findViewById(R.id.Them);
        textView8.setText("主题：" + lecture.getTheme());
        TextView textView9 = findViewById(R.id.summery);
        textView9.setText(lecture.getSummery());
//        System.out.println("111111111111111111111111111111"+lecture);
//        EditText editText = findViewById(R.id.EditText);
        getComment(lecture);






        Button button = findViewById(R.id.Button11);
//        button.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                FormBody.Builder builder = new FormBody.Builder();
//                builder.add("username", user.getUsername());
//                builder.add("activityID", "10001");
//                builder.add("data", editText.getText().toString());
//                EvaluateThread thread = new EvaluateThread(builder);
//                thread.start();
//                try {
//                    thread.join();
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                System.out.println(thread.value);
//                Toast.makeText(EvaluateActivity.this, "评价完成", Toast.LENGTH_LONG).show();
//                editText.setText("");
//            }
//        });


//        TextView textView = findViewById(R.id.TextView5);
//        textView.setText(thread.value);
    }
    //获取评论实体
    private List<Comment> getComment(Lecture lecture){
        List<Comment> commentList = new ArrayList<>();
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("actID", lecture.getActivityId());
        GetEvaluateThread thread = new GetEvaluateThread(builder);
        thread.start();
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        System.out.println("comment"+thread.value);
        JsonArray obj = new Gson().fromJson(thread.value, JsonArray.class);
        for(JsonElement jsonElement : obj){
            String userID = jsonElement.getAsJsonObject().get("userID").toString().replace("\"","");
            String activityID = jsonElement.getAsJsonObject().get("userID").toString().replace("\"","");
            String evaluateID = jsonElement.getAsJsonObject().get("userID").toString().replace("\"","");
            String data = jsonElement.getAsJsonObject().get("userID").toString().replace("\"","");
            String date = jsonElement.getAsJsonObject().get("userID").toString().replace("\"","");
            String name = jsonElement.getAsJsonObject().get("userID").toString().replace("\"","");
            Comment comment = new Comment(userID, activityID, evaluateID, data, date, name);
            commentList.add(comment);
        }
        return commentList;
    }
//    @Override
//    public void finish() {
//        super.finish();
//        //关闭activity动画显示
//        this.overridePendingTransition(0, R.anim.activity_close);
//    }

}